#pragma once

#include <windows.h>
#include <dxerr9.h>
#include <dsound.h>
#include "keyboard.h"
#include <dinput.h>
#include "Game.h"
#include "String.h"

#include "dsutil.h"

class Game;
class Audio;

//class which holds all info for a specific sound
class SFX	
{
private:
	LPDIRECTSOUNDBUFFER buffer;	//sound buffer
	int volume;		//volume level for the sound
	int volInc;		//the rate at which the sound's volume changes
	int pan;		//panning levels for sound
	int panInc;		//rate at which panning changes		
	bool looping;	//whether the sound is looping or not
	bool play;		//if true, play the sound once

	Audio* parent; //the parent audio class

public:
	SFX(Audio* prnt);
	~SFX();
	void update();
	void changeVol(bool volUp); 
	void changePan(bool panLeft);
	void changePlay() {play = !play;}
	void changeLoop() {looping = !looping;}
	void setVol(int vol) {volume = vol;}
	void setPan(int p) {pan = p;}
	void setBuff(LPDIRECTSOUNDBUFFER buff) {buffer = buff;}
	void setParent(Audio *prnt) {parent = prnt;}
	LPDIRECTSOUNDBUFFER getBuff() {return buffer;}

};


//overall audio class used for enabling sound
class Audio
{
private:
	// DirectSound functions and variables
	LPDIRECTSOUND8				g_pDS;	// The DirectSound Device


public:
	Game *parent;

	Audio(Game *prnt);
	~Audio();
	bool Init();
	void update();
	bool initDirectSound(HWND hwnd);
	void shutdownDirectSound(void);
	LPDIRECTSOUNDBUFFER LoadWaveToSoundBuffer(std::string wavFilename);
	void playSound(LPDIRECTSOUNDBUFFER whichBuffer);
	void playSoundLoop(LPDIRECTSOUNDBUFFER whichBuffer);
	void stopSound(LPDIRECTSOUNDBUFFER whichBuffer);
	void setParent(Game *prnt) {parent = prnt;}

	//hey look, sounds!
	SFX* rave;
	SFX* beep;
	SFX* kirby;
};